package com.woniu.controller;

import com.woniu.entity.Warehouse;
import com.woniu.service.WarehouseService;
import com.woniu.util.ResponseUtil;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/warehouse")
public class WarehouseController {

    @Resource
    private WarehouseService warehouseService;

    // 新增仓库
    @PostMapping("/add")
    public ResponseUtil addWarehouse(@RequestBody Warehouse warehouse) {
        return warehouseService.addWarehouse(warehouse);
    }

    // 删除仓库
    @DeleteMapping("/delete/{id}")
    public ResponseUtil deleteWarehouse(@PathVariable("id") Integer warehouseId) {
        return warehouseService.deleteWarehouse(warehouseId);
    }

    // 更新仓库
    @PutMapping("/update")
    public ResponseUtil updateWarehouse(@RequestBody Warehouse warehouse) {
        return warehouseService.updateWarehouse(warehouse);
    }

    // 根据ID查询仓库
    @GetMapping("/get/{id}")
    public ResponseUtil getWarehouseById(@PathVariable("id") Integer warehouseId) {
        return warehouseService.getWarehouseById(warehouseId);
    }

    // 查询所有仓库
    @GetMapping("/getAll")
    public ResponseUtil getAllWarehouses() {
        return warehouseService.getAllWarehouses();
    }

    // 模糊查询
    @GetMapping("/search")
    public ResponseUtil searchWarehouses(
            @RequestParam(required = false) String name,
            @RequestParam(required = false) String address) {
        return warehouseService.searchWarehouses(name, address);
    }

    // 停用仓库
    @PutMapping("/disable/")
    public ResponseUtil disableWarehouse(@RequestBody Warehouse warehouse) {
        return warehouseService.disableWarehouse(warehouse);
    }
}
